package cn.mw.cmdb.config;

import cn.mw.microMonitorCommon.json.CustomerModule;
import org.apache.commons.collections.CollectionUtils;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.spring.security.jackson.ObjectMapperCodec;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class JsonDeserializerConfig implements CommandLineRunner {
    @Override
    public void run(String... args) throws Exception {
        List<ObjectMapperCodec> objectMapperCodecList = ApplicationModel.defaultModel().getBeanFactory().getBeansOfType(ObjectMapperCodec.class);
        if (CollectionUtils.isNotEmpty(objectMapperCodecList)) {
            ObjectMapperCodec objectMapperCodec = objectMapperCodecList.get(0);
            objectMapperCodec.addModule(new CustomerModule());
        }
    }
}
